<template>
  <div class="login-phone">
    <el-form label-width="70px" :rules="rules" :model="account" ref="formRef">
      <el-form-item label="手机号" prop="phone">
      <el-input v-model="account.phone" maxlength="11"/>
      </el-form-item>
      <el-form-item label="验证码" prop="code">
        <div style="display:flex">
          <el-input v-model="account.code" maxlength="4"/>
          <div style="width:20px"></div>
          <el-button type="primary" size="small">获取验证码</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { ElForm } from "element-plus";
import { defineComponent, reactive ,ref} from "vue";
import { rules } from '../config/account-config';
import localCache from '@/utils/cache';
import { useStore } from 'vuex'

export default defineComponent({
  setup() {
    //拿到vuex
    const store = useStore()
    const formRef = ref<InstanceType<typeof ElForm>>()

    const account = reactive({
      phone:'',
      code:''
    })
    const loginAction = () => {
      // console.log(1245121)
       formRef.value?.validate((valid) => {
        //  console.log(valid)
         if(valid){
          //开始进行登录验证
          store.dispatch('login/phoneLoginAction',{...account})
         }
       })
    }

    return {
      account,
      rules,
      formRef,
      loginAction,
    }
  }
})
</script>

<style lang="less" scoped>

</style>
